import axios from 'axios'
export default function request(params) {
  if (typeof params !== 'object') {
    throw Error('所传参数必须是对象')
  } else {
    //创建一个axios实例
    const instance = axios.create({
      baseURL: '/v1',
      timeout: 5000
    })
    //axios进行配置
    //axios进行拦截
    instance.interceptors.request.use(function (config) {
      return config
    }, function (error) {
      return Promise.reject(error)
    })
    instance.interceptors.response.use(function (res) {
      return res.data
    }, function (error) {
      return Promise.reject(error)
    })
    return instance(params)
  }
}